package com.aks.server.domain.response;

import com.aks.server.domain.response.em.ResultEnum;
import lombok.Data;

/**
 * 响应结果类
 *
 * @param <T> 任意类型
 */
@Data
public class ResponseResult<T> {
    /**
     * 异常编号
     */
    private String errorCode;
    /**
     * 异常信息
     */
    private String message;
    /**
     * 响应数据
     */
    private T data;



    public static <T> ResponseResult<T> fail(ResultEnum resultEnum) {
        return fail(resultEnum.getCode(), resultEnum.getMessage(), null);
    }



    public static <T> ResponseResult<T> success(ResultEnum resultEnum, T data) {
        ResponseResult<T> r = new ResponseResult<>();
        r.setErrorCode(resultEnum.getCode());
        r.setMessage(resultEnum.getMessage());
        r.setData(data);
        return r;
    }

    public static <T> ResponseResult<T> fail(String errorCode, String message, T data) {
        ResponseResult<T> r = new ResponseResult<>();
        r.setErrorCode(errorCode);
        r.setMessage(message);
        r.setData(data);
        return r;
    }

}